
<template>
  <el-scrollbar>
    <div class="el-scrollbar__wrap">
      <div class="login-container">
        <div class="shadow" />
        <video
          data-v-81300996=""
          src="https://slwl-admin.itheima.net/static/media/video.3cf57b17.mp4"
          autoplay="autoplay"
          loop="loop"
          muted="muted"
          style="width: 100%; height: 100%; object-fit: fill"
        />

        <el-form
          ref="loginForm"
          :model="loginForm"
          class="login-form"
          auto-complete="on"
          label-position="left"
          :rules="rules"
        >
          <div class="title-container">
            <img
              src="	https://slwl-admin.itheima.net/static/img/logo1.33ef7fa0.png"
              alt=""
              width="195px"
              height="54px"
            >
          </div>

          <el-form-item prop="username">
            <span class="svg-container">
              <svg-icon icon-class="user" />
            </span>
            <el-input
              ref="username"
              v-model="loginForm.username"
              placeholder="Username"
              name="username"
              type="text"
              tabindex="1"
              auto-complete="on"
            />
          </el-form-item>

          <el-form-item prop="password">
            <span class="svg-container">
              <svg-icon icon-class="password" />
            </span>
            <el-input
              :key="passwordType"
              ref="password"
              v-model="loginForm.password"
              :type="passwordType"
              placeholder="Password"
              name="password"
              tabindex="2"
              auto-complete="on"
              @keyup.enter.native="handleLogin"
            />
            <span class="show-pwd" @click="showPwd">
              <svg-icon
                :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
              />
            </span>
          </el-form-item>

          <el-form-item prop="code">
            <span class="svg-container">
              <svg-icon icon-class="table" />
            </span>
            <el-input
              v-model="loginForm.code"
              class="input"
              placeholder="请输入右侧计算结果"
            />
            <img :src="imgUrl" class="validateImg" @click="changeCode">
            <!-- <img :src="imgUrl" class="validateImg" @click="changeCode"> -->
          </el-form-item>

          <el-button
            :loading="loading"
            style="width: 100%; margin-bottom: 30px"
            @click="hLogin"
          >登录</el-button>

          <div class="tips">
            仅用于IT培训教学使用，为保障您的个人信息安全，请勿向平台录入任何个人敏感信息（如手机号、身份证号等）！
          </div>
        </el-form>

        <div class="login-footer">
          江苏传智播客教育科技股份有限公司
          <span
            data-v-81300996=""
            style="margin-left: 20px"
          >版权所有Copyright 2006-2022 All Rights Reserved</span>
          <span
            data-v-81300996=""
            style="margin-left: 20px"
          >苏ICP备16007882号-11</span>
        </div>
      </div>
    </div>
  </el-scrollbar>
</template>

<script>
import { getCode } from '@/api/user'
// import { Message } from 'element-ui'
import { randomNum } from '@/utils'
export default {
  name: 'Login',
  data() {
    return {
      imgUrl: '',
      // 请求登录接口的参数
      key: randomNum(),
      loginForm: {
        username: 'shenlingadmin',
        password: '123456',
        code: ''

      },
      loading: false,
      passwordType: 'password',
      rules: {
        username: [
          { required: true, message: '账户名不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }

        ],
        code: [
          { required: true, message: '请输入计算结果', trigger: 'blur' }

        ]
      }
    }
  },
  created() {
    this.getCode()
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    // 获取验证码到图片路径并解码
    async getCode() {
      const res = await getCode(this.key)
      console.log(res)
      const url = URL.createObjectURL(res) // 转化为路径
      this.imgUrl = url
    },
    // 点击获取验证码
    changeCode() {
      this.getCode()
    },
    hLogin() {
      // 兜底校验
      this.$refs.loginForm.validate((val) => {
        val && this.tohLogin()
        this.$router.push('/')
      })
    },
    toLogin() {
      console.log('发送请求')
    }

  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 5px;
      padding: 12px 5px 12px 15px;
      height: 47px;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
  .validateImg {
    display: inline-block;
    vertical-align: top;
    width: 71px;
    height: 32px;
    cursor: pointer;
    margin-left: 10px;
    position: absolute;
    right: 10px;
    top: 9px;
  }
}
</style>

<style lang="scss" scoped>
$bg: #ccc;
$dark_gray: #889aa4;
$light_gray: #bac0cd;

video{
position: absolute;
// background-size: 100% 100%;
}
.el-scrollbar {
  overflow: hidden;
  position: relative;
  height: 100%;
  width: 100%;
}
#app .el-scrollbar__wrap {
  overflow-x: hidden;
  margin-bottom: -17px;
  margin-right: -17px;
}
.login-container {
  min-height: 100%;
  width: 100%;
  overflow: hidden;
  background: $bg;

  .shadow {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.3;
    background: #1a1c41;
  }

  .login-form {
    position: absolute;
    top: 45%;
    left: 45%;
    margin: -180px 0 0 -160px;
    width: 450px;
    height: 490px;
    padding: 36px 40px;
    background: #fff;
    border-radius: 10px;

    .title-container {
      position: relative;
      margin-bottom: 28px;
      text-align: center;
    }
  }

  button {
    width: 100%;
    height: 54px;
    margin-bottom: 14px;
    background-color: #e15536;
    border: 0;
    font-size: 18px;
    color: #fff;
    font-weight: 700;
  }

  .tips {
    line-height: 20px;
    font-size: 14px;
    color: #fd3333;
    margin-bottom: 20px;
  }

  .login-footer {
    font-size: 14px;
    color: white;
    text-align: center;
    position: absolute;
    bottom: 5%;
    left: 0%;
    width: 100%;
    opacity: 0.9;
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
